///////////////////////////////////////////////////////////////////////////
//																		 //
//	Author:		Michael Mozdzierz										 //
//	Date:		10/25/2014												 //
//	Purpose:	Define a particle, the smallest unit in the particle	 //
//				system													 //
//																		 //
///////////////////////////////////////////////////////////////////////////

#ifndef _PARTICLE_H
#define _PARTICLE_H

#include "../../EdgeMath\Vectors.h"
#include "../../EdgeGraphics\IDrawable.h"
#include "../../EdgeGraphics/Material.h"
class VertexBuffer;
class ShaderContainer;

// Defines behavior for a particle
struct Particle : public IDrawable
{
	/////////////////////<Public members>//////////////////////////////////////////

	// starting blend color for the particle
	Vector4 start_color;
	// ending blend color of the particle
	Vector4 end_color;

	// position of the particle
	Vector3 position;
	// velocity of the particle
	Vector3 velocity;
	// acceleration for the particle
	Vector3 acceleration;

	// the texture the particle uses when drawing
	Material* texture;

	// the current rotation, in radians of the particle
	float rotation = 0.f;
	// the rate of change in rotation for the particle
	float rotation_speed = 0.f;

	// the alpha the particle has at the begining of its lifetime
	float start_alpha = 1.f;
	// the alpha the partile has at the end of its lifetime
	float end_alpha = 1.f;

	// the scale of the particle at the begining of the particles life
	float start_size = 1.f;
	// the scale of the particle at the end of its life
	float end_size = 1.f;

	// the total ammount of time this particle will live
	float max_lifetime;
	// the ammount of time this particle has left to live
	float lifetime;

	// indicates that the particle is currently in use
	bool isAlive = false;

	Particle(void);
	virtual ~Particle(void);	
	
	/////////////////////////////////////////////////////////////
	// Implament IDrawable
	/////////////////////////<Accessors>///////////////////////////////////////////////////

	virtual VertexBuffer* getVertexBuffer(void) const override { return vBuffer; }

	virtual IGraphicsResource** getResourceViews(void) const override { return (IGraphicsResource**)texture->textures.e; }

	virtual int getNumResourceViews(void) const { return Material::numTextures; }

	virtual ShaderContainer* getShaderContainer(void) const override { return shader_container; }

	virtual Matrix getWorldTransform(void) const { return VectorHelper::Matricies::Identity; }

	/////////////////////////<Mutators>///////////////////////////////////////////////////

	virtual void setResourceView(IGraphicsResource* value, unsigned int index) override;

	virtual void setShaderContainer(ShaderContainer* value) override { /*do nothing*/ }

	/////////////////////<Public functions >//////////////////////////////////////////

	// update the particle
	void Update(float dt);

	// get the current alpha, based on lifetime
	float getCurrentAlpha(void) const { return alpha; }
	// get the current size, based on lifetime
	float getCurrentSize(void) const { return size; }
	// get the current color, based on lifetime
	Vector4 getCurrentColor(void) const { return color; }

private:

	// the current alpha of this particle
	float alpha = 0.f;
	// the current size of this particle
	float size = 0.f;
	// the current color of this particle
	Vector4 color;

	static VertexBuffer* vBuffer;

	static ShaderContainer* shader_container;
};

#endif